<?php
/**
 * isNull()
 *
 * @param string $mTarget
 * @return boolean
 */
function isNull($mValue = "")
{
    return ("" == trim($mValue) && null == trim($mValue))?true:false;
}
/**
 * isUserName()
 *
 * @param string $mValue
 * @return boolean
 */
function isUserName($sUserName = "")
{
    return ereg("^[a-zA-Z][a-zA-Z0-9_]{4,15}$", $sUserName)?true:false;
}
/**
 * isFiltrate()
 *
 * @param string $mValue
 * @return boolean
 */
function isFiltrate($mValue = "")
{
    return ereg("([;,%()?|/\$&+=:!]+)", $mValue)?true:false;
}
/**
 * isSame()
 *
 * @param string $mValue1
 * @param string $mValue2
 * @return boolean
 */
function isSame($mValue1 = "", $mValue2 = "")
{
    return ($mValue1 == $mValue2)?true:false;
}
/**
 * isStrongPwd()
 *
 * @param string $pwd
 * @return
 */
function isStrongPwd($sPwd = "")
{
    return preg_match("^(?=.*\d)(?=.*[a-z])(?=.*[A-Z]).{8,10}$^", $sPwd)?true:false;
}
/**
 * isLongPwd()
 *
 * @param string $sPwd
 * @return boolean
 */
function isLongPwd($sPwd = "")
{
    return ereg("^[a-zA-Z0-9_@#-]{6,}$", $sPwd)?true:false;
}
/**
 * isAuthcode()
 *
 * @param string $authcode
 * @return boolean
 */
function isAuthcode($sAuthcode = "")
{
    return ($_SESSION['authcode'] == md5($sAuthcode))?true:false;
}
/**
 * isChineseChar()
 *
 * @param string $sFormStr
 * @return boolean
 */
function isChineseChar($sChineseChar = "")
{
    return ereg("[u4e00-u9fa5]", $sChineseChar)?true:false;
}
/**
 * isIdCard()
 *
 * @param string $sFormStr
 * @return boolean
 */
function isIdCard($sIdcard = "")
{
    return ereg("(^[0-9]{18}$)|(^[0-9]{17}X$)", $sIdcard)?true:false;
}
/**
 * isDate()
 *
 * @param string $sDate
 * @return boolean
 */
function isDate($sDate = "")
{
    return ereg("^((((19|20)(([02468][048])|([13579][26]))-02-29))|((20[0-9][0-9])|(19[0-9][0-9]))-((((0[1-9])|(1[0-2]))-((0[1-9])|(1\d)|(2[0-8])))|((((0[13578])|(1[02]))-31)|(((0[1,3-9])|(1[0-2]))-(29|30)))))$", $sDate)?true:false;
}
/**
 * isIdCardFitBirthday()
 *
 * @param string $sIdCard
 * @param string $sBirthday
 * @return boolean
 */
function isIdCardMatchBirthday($sIdCard = "", $sBirthday = "")
{
    if (isIdCard($sIdCard) && isDate($sBirthday)) {
        $idcard = substr($sIdCard, 6, 8);
        $birthday = substr($sBirthday, 0, 4) . substr($sBirthday, 5, 2) . substr($sBirthday, 8, 2);
        return (isSame($idcard, $birthday))?true:false;
    } else {
        return false;
    }
}
/**
 * isEmail()
 *
 * @param string $sEmail
 * @return boolean
 */
function isEmail($sEmail = "")
{
    return ereg("^[_a-zA-Z0-9-]+(\.[_a-zA-Z0-9-]+)*@[a-zA-Z0-9-]+(\.[a-zA-Z0-9-]+)*\.(([0-9]{1,3})|([a-zA-Z]{2,3})|(aero|coop|info|museum|name))$", $sEmail)?true:false;
}
/**
 * isCellPhone()
 *
 * @param string $sPhone
 * @return boolean
 */
function isCellPhone($sPhone = "")
{
    return ereg("(^13[0-9]{1}[0-9]{8}$)|(^15[9]{1}[0-9]{8}$)", $sPhone)?true:false;
}
/**
 * isHomePhone()
 *
 * @param string $sPhone
 * @return boolean
 */
function isHomePhone($sPhone = "")
{
    return ereg("(^[0-9]{3,4}-[0-9]{7,8}$)|(^[1-9]{1}[0-9]{6,7}$)", $sPhone)?true:false;
}
/**
 * isQQ()
 *
 * @param string $sQQ
 * @return boolean
 */
function isQQ($sQQ = "")
{
    return ereg("[1-9][0-9]{4,}", $sQQ)?true:false;
}
/**
 * isZipcode()
 *
 * @param string $sZipcode
 * @return boolean
 */
function isZipcode($sZipcode = "")
{
    return ereg("^[1-9][0-9]{5}", $sZipcode)?true:false;
}
/**
 * isAgree()
 *
 * @param mixed $bAgree
 * @return boolean
 */
function isAgree($bAgree = false)
{
    return $bAgree;
}
/**
 * isValidUser()
 *
 * @param string $sUserName
 * @param string $sUserPwd
 * @return boolean
 */
function isValidUser($sUserName = "", $sUserPwd = "")
{
    $sql = "SELECT user_name,user_pwd FROM " . DB_PREFIX . "user_auth WHERE user_name = '" . $sUserName . "'";
    // TO DO:
    $result = zeus_sql_query($sql, false);
    return (($result['user_name'] == $sUserName) && ($result['user_pwd'] == md5($sUserPwd)))?true:false;
}
/**
 * isEnableUser()
 *
 * @param string $sUserName
 * @return boolean
 */
function isEnableUser($sUserName = "")
{
    $sSql = "SELECT * FROM " . DB_PREFIX . "user_auth WHERE user_name = '" . $sUserName . "'";
    $aResult = getVar($sSql, false);
    $enable = $aResult[0]['is_enable'];
    return (1 == $enable)?true:false;
}
/**
 * isExistUser()
 *
 * @param string $sUserName
 * @return boolean
 */
function isExistUser($sUserName = "")
{
    $sql = "SELECT user_id FROM " . DB_PREFIX . "user_auth WHERE user_name = '" . $sUserName . "'";
    $result = zeus_sql_query($sql, false);
    if (isset($result) && null != $result['user_id']) {
        return true;
    } else {
        return false;
    }
}
/**
 * isExistEmail()
 *
 * @param string $sEmail
 * @return
 */
function isExistEmail($sEmail = "")
{
    $sql = "SELECT email FROM " . DB_PREFIX . "user_detail WHERE email = '" . $sEmail . "'";
    $result = zeus_sql_query($sql, false);
    if (isset($result) && null != $result['email']) {
        return true;
    } else {
        return false;
    }
}
/**
 * isExistSportName()
 *
 * @param string $sSportName
 * @return
 */
function isExistSportName($sSportName = "")
{
    $sql = "SELECT sport_id FROM " . DB_PREFIX . "sport WHERE sport_name = '" . $sSportName . "'";
    $result = zeus_sql_query($sql, false);
    if (isset($result) && null != $result['sport_id']) {
        return true;
    } else {
        return false;
    }
}

/**
 * isExistRoleName()
 *
 * @param string $sRoleName
 * @return
 */
function isExistRoleName($sRoleName = "")
{
    $sql = "SELECT role_id FROM " . DB_PREFIX . "role WHERE role_name = '" . $sRoleName . "'";
    $result = zeus_sql_query($sql, false);
    if (isset($result) && null != $result['role_id']) {
        return true;
    } else {
        return false;
    }
}

/**
 * getFileType()
 *
 * @param string $sFileName
 * @return
 */
function getFileType($sFileName = "")
{
    $file = fopen($sFileName, "rb");
    $bin = fread($file, 2);
    fclose($file);
    $strInfo = @unpack("c2chars", $bin);
    $typeCode = intval($strInfo['chars1'] . $strInfo['chars2']);
    // echo $typeCode;
    $fileType = "";
    switch ($typeCode) {
        case 7790:
            $fileType = "exe";
            break;
        case 7784:
            $fileType = "midi";
            break;
        case 8297:
            $fileType = "rar";
            break;
        case 255216:
            $fileType = "jpg";
            break;
        case 7173:
            $fileType = "gif";
            break;
        case 6677:
            $fileType = "bmp";
            break;
        case 13780:
            $fileType = "png";
            break;
        default:
            $fileType = "unknown";
            break;
    }
    return $fileType;
}

?>